<template>
	<view>
		<view class="set_form_box">
			<view class="set_form_item_box" @click="goArticle(2)">
				<view class="set_form_item_left">用户服务协议</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(1)">
				<view class="set_form_item_left">隐私政策</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(3)">
				<view class="set_form_item_left">保证金扣除规则</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(4)">
				<view class="set_form_item_left">结算细则</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(5)">
				<view class="set_form_item_left">奖励规则</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(6)">
				<view class="set_form_item_left">骑士安全管理规则</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(7)">
				<view class="set_form_item_left">骑士管理说明</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(8)">
				<view class="set_form_item_left">违禁品规定</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(9)">
				<view class="set_form_item_left">骑手须知协议一</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(10)">
				<view class="set_form_item_left">骑手须知协议二</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(11)">
				<view class="set_form_item_left">骑手须知协议三</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(12)">
				<view class="set_form_item_left">骑手须知协议四</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(13)">
				<view class="set_form_item_left">骑手须知协议五</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
			<view class="set_form_item_box" @click="goArticle(14)">
				<view class="set_form_item_left">骑手须知协议六</view>
				<view class="set_form_item_right">
					<image src="https://www.cccshansong.com/chong_weapp/set_icon.png" mode=""></image>
				</view>
			</view>
		</view>
		<view  style="height: 200rpx;"></view>
	</view>
</template>

<script>
	// #ifdef APP-PLUS
	import APPUpdate from "../../js_sdk/zhouWei-APPUpdate/APPUpdate/index.js";
	// #endif
	export default {
		data() {
			return {
				version:'',
				fileSizeString:'',
				is_checked1:true,
				is_checked2:true,
			};
		},
		onLoad() {
			var a = this
			a.getUserInfo()
			a.getFormatSize()
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, (widgetInfo)=> {
				this.version = widgetInfo.version
			});
			// #endif
		},
		methods:{
			// 获取缓存
			getFormatSize(){
				// #ifdef APP-PLUS
				plus.cache.calculate((size) => {
					let sizeCache = parseInt(size);
					if (sizeCache == 0) {
						this.fileSizeString = "0B";
					} else if (sizeCache < 1024) {
						this.fileSizeString = sizeCache + "B";
					} else if (sizeCache < 1048576) {
						this.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
					} else if (sizeCache < 1073741824) {
						this.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
					} else {
						this.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
					}
				});
				// #endif
			},
			handleUpdate() {
				uni.setStorageSync('versionTost',true)
				// #ifdef APP-PLUS
				APPUpdate();
				// #endif
			},
			goArticle(id){
				uni.navigateTo({
					url:'/pages/user/articleDetail?id=' + id
				})
			},
			handleClear(){
				this.$showModal({
					title:'提示',
					content:'您确定要清除缓存吗？',
					showCancel:true,
					confirmText:'确定',
					success: (res) => {
						if(res.confirm){
							this.clearCache();
						}
					}
				});
			},
			clearCache() {
				let os = plus.os.name;
				var a = this
				uni.showLoading({
					title:'加载中'
				})
				setTimeout(()=>{
					uni.hideLoading()
					if (os == 'Android') {
						let main = plus.android.runtimeMainActivity();
						let sdRoot = main.getCacheDir();
						let files = plus.android.invoke(sdRoot, "listFiles");
						let len = files.length;
						for (let i = 0; i < len; i++) {
							let filePath = '' + files[i];
							plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
								if (entry.isDirectory) {
									entry.removeRecursively((entry)  => {
										uni.showToast({
											title: '缓存清理完成',
											icon:'none',
											duration: 2000
										});
										a.getFormatSize();
									}, (e) => {
										a.show_refresh = false
										console.log(e.message)
									});
								} else {
									entry.remove();
								}
							}, (e) => {
								a.show_refresh = false
								console.log('文件路径读取失败')
							});
						}
					} else { // ios
						plus.cache.clear(() =>{
							uni.showToast({
								title: '缓存清理完成',
								icon:'none',
								duration: 2000
							});
							a.getFormatSize();
						});
					}
				},1000)
			},
			getUserInfo(){
				var a =this
				uni.showLoading({
					title:'加载中'
				})
				a.globalajax('user/info',{
					},'GET',function(res) {
						console.log(res);
						uni.hideLoading()
						uni.stopPullDownRefresh()
						if(res.data.code==200){
							if(res.data.data.info.is_message==0){
								a.is_checked1 = false
							}else{
								a.is_checked1 = true
							}
							if(res.data.data.info.is_voice==0){
								a.is_checked2 = false
							}else{
								a.is_checked2 = true
							}

						}else{
							a.$showModal({
								title:'友情提示',
								content:res.data.msg,
								showCancel:false,
								confirmText:'我知道了',
								success: (res) => {
								}
							});
						}
					}
				);
			},
			switch1Change(e){
				console.log(e)
				this.is_checked1 = e.detail.value
				if(e.detail.value){
					this.handleChange1(1)
				}else{
					this.handleChange1(0)
				}
			},
			handleChange1(index){
				var a = this
				uni.showLoading({
					title:'加载中'
				})
				a.globalajax('user/modify',{
					is_message:index,
					lat: uni.getStorageSync('latitude'),
					lng: uni.getStorageSync('longitude'),
					},'POST',function(res) {
						console.log(res);
						uni.hideLoading()
						uni.stopPullDownRefresh()
						if(res.data.code==200){
						}else{
							a.$showModal({
								title:'友情提示',
								content:res.data.msg,
								showCancel:false,
								confirmText:'我知道了',
								success: (res) => {
								}
							});
						}
					}
				);
			},
			switch2Change(e){
				console.log(e)
				this.is_checked2 = e.detail.value
				if(e.detail.value){
					this.handleChange2(1)
				}else{
					this.handleChange2(0)
				}
			},
			handleChange2(index){
				var a = this
				uni.showLoading({
					title:'加载中'
				})
				a.globalajax('user/modify',{
					is_voice:index,
					lat: uni.getStorageSync('latitude'),
					lng: uni.getStorageSync('longitude'),
					},'POST',function(res) {
						console.log(res);
						uni.hideLoading()
						uni.stopPullDownRefresh()
						if(res.data.code==200){
						}else{
							a.$showModal({
								title:'友情提示',
								content:res.data.msg,
								showCancel:false,
								confirmText:'我知道了',
								success: (res) => {
								}
							});
						}
					}
				);
			},
			//跳转手机系统设置
			goSetting() {
				if (plus.os.name == "iOS") {
					var UIApplication = plus.ios.import("UIApplication");
					var application2 = UIApplication.sharedApplication();
					var NSURL2 = plus.ios.import("NSURL");
					var setting2 = NSURL2.URLWithString("app-settings:");
					application2.openURL(setting2);
					plus.ios.deleteObject(setting2);
					plus.ios.deleteObject(NSURL2);
					plus.ios.deleteObject(application2);
				} else {
					var Intent = plus.android.importClass("android.content.Intent");
					var Settings = plus.android.importClass("android.provider.Settings");
					var Uri = plus.android.importClass("android.net.Uri");
					var mainActivity = plus.android.runtimeMainActivity();
					var intent = new Intent();
					intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
					var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
					intent.setData(uri);
					mainActivity.startActivity(intent);
				}
			},
			goSet(index){
				if(index==0){
					this.goSetting()
				}else if(index==1){
					uni.navigateTo({
						url:'/pages/user/editPwd'
					})
				}else if(index==2){
					uni.navigateTo({
						url:'/pages/user/bindPhone'
					})
				}
			},
		}
	}
</script>

<style lang="scss">
page{
	background-color: #f5f6f8;
}
.set_title{
	height: 92rpx;
	line-height: 92rpx;
	text{
		color: #000000;
		font-size: 30rpx;
		margin-left: 32rpx;
	}
}
.set_form_box{
	background-color: #fff;
	.set_form_item_box{
		width: 750rpx;
		height: 96rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 2rpx solid rgba(235, 238, 245, 1);
		.set_form_item_left{
			margin-left: 32rpx;
			color: rgba(48, 49, 51, 1);
			font-size: 30rpx;
		}
		.set_form_item_right{
			display: flex;
			align-items: center;
			text{
				margin-right: 4rpx;
				font-size: 28rpx;
			}
			switch{
				margin-right:16rpx;
			}
			image{
				width: 44rpx;
				height: 44rpx;
				margin-right: 16rpx;
			}
		}
	}
}
</style>
